import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './styles/index.scss'
import * as filters from './filters'
import './utils/error-handler'
import { initMonitor } from './utils/monitor'

// 导入 ECharts
import ECharts from 'vue-echarts'
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/bar'
import 'echarts/lib/chart/pie'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/title'
import 'echarts/lib/component/legend'
import 'echarts/lib/component/legendScroll'
import 'echarts/lib/component/grid'
import 'echarts/lib/component/dataZoom'

// 全局注册 ECharts 组件
Vue.component('v-chart', ECharts)

Vue.use(ElementUI)

// 注册全局过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

// 添加全局错误处理
Vue.config.errorHandler = (err, vm, info) => {
  console.error('Vue Error:', err)
  console.error('Error Info:', info)
  console.error('Component:', vm)
}

// 初始化监控系统
try {
  initMonitor(Vue, App)
} catch (error) {
  console.error('Failed to initialize monitor:', error)
}

// 创建 Vue 实例
const app = new Vue({
  router,
  store,
  render: h => h(App)
})

// 添加全局错误处理
window.addEventListener('unhandledrejection', event => {
  console.error('Unhandled Promise Rejection:', event.reason)
})

// 挂载应用
app.$mount('#app') 